package com.wisezone.demo0216;

import java.io.*;
import java.net.URL;

public class TestURL {
    public static void main(String[] args) {
        try{
//            URL url = new URL("https://www.tupianzi.com/");
//            URL fileURL = new URL(url,"https://gitee.com/");
//            System.out.println(fileURL.getQuery());
            URL url = new URL("http://www.win4000.com/wallpaper_detail_158950_8.html");
            InputStream is = url.openStream();
            File file = new File("out/02.jpg");
            FileOutputStream fileOutputStream = new FileOutputStream(file);

            int length = 0;
            byte[] bytes = new byte[1024];
            while ((length=is.read(bytes))!=-1){
                fileOutputStream.write(bytes,0,length);
            }
            fileOutputStream.flush();


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
